<%@page import="java.util.ArrayList"%>
<%@page import="models.GeoModel"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.TreeMap"%>
<%@page import="helpers.UrlHelper"%>

<%
TreeMap check = (TreeMap) request.getAttribute("check");
String success = (String) request.getAttribute("success");
GeoModel geo = (GeoModel) request.getAttribute("geo");
ArrayList<GeoModel> geos = (ArrayList<GeoModel>) request.getAttribute("geos");
String form = (String) request.getAttribute("form");
%>

<jsp:include page="/admin/layouts/header.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>

<script type="text/javascript" src="/admin/js/form_geo.js"></script>

		<div class="maincontent noright">
        	<div class="maincontentinner">
                <ul class="maintabmenu multipletabmenu">
                	<li><a href="/admin/geo/list">Danh sách khu vực</a></li>
                	<li class="current"><a href="/admin/geo/add"><%=form.equalsIgnoreCase("edit") ? "Cập nhật khu vực" : "Thêm khu vực" %></a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">
					<% if (success != null) {%>
					<div class="notification msgsuccess">
                        <a class="close"></a>
                        <p><%=success %></p>
                    </div>
					<% } %>
                    <div class="contenttitle">
                    	<h2 class="form"><span>Thông tin địa lý</span></h2>
                    </div><!--contenttitle-->
            
                    <form method="post" action="#" class="stdform stdform2" id="edit_config_form">
                    	<p>
                        	<label>Mã</label>
                            <span class="field">
                            	<%=geo.getGeoId() %>
                            	<input type="hidden" value="<%=geo.getGeoId() %>" name="geoId">
                            </span>
                        </p>
                        
                        <p>
                        	<label>Tên</label>
                            <span class="field">
                            	<input type="text" class="smallinput" name="name" id="g_name" value="<%=geo.getName() != null ? geo.getName() : "" %>">
                            	<% if (check.get("name") != null) { %>
									<label for="g_name" generated="true" class="error"><%=check.get("name") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Viết tắt</label>
                            <span class="field">
                            	<input type="text" class="smallinput" name="alias" id="g_alias" value="<%=geo.getAlias() != null ? geo.getAlias() : "" %>">
                            	<% if (check.get("alias") != null) { %>
									<label for="g_alias" generated="true" class="error"><%=check.get("alias") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Trực thuộc</label>
                            <span class="field">
                            	<select id="g_parentId" name="parentId" <%=form.equalsIgnoreCase("edit") ? "disabled=\"disabled\"" : "" %>>
                            		<option value="0">(Không)</option>
                            		<% for (int i = 0; i < geos.size(); i++) { %>
                            		<option value="<%=geos.get(i).getGeoId()%>" <%=geo.getParentId().equalsIgnoreCase(geos.get(i).getGeoId()) ? "selected=\"selected\"" : "" %>>
                            		|<% for (int j = 1 ; j <= geos.get(i).getLevel(); j++) {%>&nbsp;&nbsp;&nbsp;&nbsp;|<% } %>___
                            			<%=geos.get(i).getName()%>
                            		</option>
                            		<% } %>
                            	</select>
                            	 <% if (check.get("parentId") != null) { %>
									<label for="g_parentId" generated="true" class="error"><%=check.get("parentId") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p>
                        	<label>Loại địa danh</label>
                            <span class="field">
                            	<select id="g_type" name="type" >
                            		<option value="city" <%=geo.getType().equalsIgnoreCase("city") ? "selected=\"selected\"" : "" %>>Tỉnh/Thành phố</option>
                            		<option value="district" <%=geo.getType().equalsIgnoreCase("district") ? "selected=\"selected\"" : "" %>>Quận/Huyện</option>
                            		<option value="ward" <%=geo.getType().equalsIgnoreCase("ward") ? "selected=\"selected\"" : "" %>>Phường/Xã</option>
                            	</select>
                           	 	<% if (check.get("type") != null) { %>
									<label for="g_type" generated="true" class="error"><%=check.get("type") %></label>
								<% } %>
                            </span>
                        </p>
                        
                        <p class="stdformbutton">
                        	<button class="submit radius2">Cập nhật</button>
                            <input type="reset" value="Trở lại ban đầu" class="reset radius2">
                        </p>
                        
                    </form>
                    
                    <br clear="all">
                    
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp">
            	<jsp:param name="language" value="1" />
			</jsp:include>
            
        </div>

<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>